<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 1. 先准备一个容器 -->
    <div id="app">
        <ul v-for="item in list">
            <li>{{item.num}} 
                <button @click="del(item.id)">删除</button>
            </li>
           
        </ul>
        <button @click="born">生成</button>
    </div>
    <!-- 2. 引框架 -->
    <script src="./vue.js"></script>
    <script>
      // 3.初始化vue实例对象
      const vm = new Vue({
        el: "#app",
        data: {
            num:1,
            list:[
                {id:1,num:Math.floor(Math.random()*20)},
                {id:2,num:Math.floor(Math.random()*20)},
                {id:3,num:Math.floor(Math.random()*20)},
            ]
        },
        methods:{
            del(id){
                const index=this.list.findIndex(item=>item.id===id);
                this.list.splice(index,1)
            },
            born() {
              const obj={id:+new Date(),num:Math.floor(Math.random()*20)}
             this.list.push(obj)
            }

        }
      });
    </script>
  </body>
</html>
